


<style lang="scss" scoped>
#interaction {
    background: #fff;
    padding: 10px;
    .g-card{
       min-height:300px;
       padding:10px;
       background:#fff;
       &.g-card-null{
            margin-left:-10px;
            margin-top:-10px;
        }
   }
}
</style>
<template>
    <div id="interaction">
        <div class="g-card">
            <el-table v-loading="loading" element-loading-text="数据加载中，请稍后" empty-text="暂无相互作用药物" :data='intInfo' border style="width: 100%">
                <el-table-column width="200" align="center" label="药品名称" prop='drugName'></el-table-column>
                <el-table-column width="200" align="center" label="相互作用的药品" prop='medicine'></el-table-column>
                <el-table-column align="center" label="作用效果" prop='effect'></el-table-column>
                <el-table-column width="100" align="center" label="详情">
                    <template slot-scope="scope">
                        <a @click="goIntDetails(scope.row)" href="javascript:void(0)">详情</a>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>


<script>
import { medicine } from "api/index.js";
export default {
    name: "interaction", //药物相互作用
    data() {
        return {
            drugId:"",
            searchStrDrugA:"",
            searchStrDrugAId:"",
            searchStrDrugB:"",
            loading: false,
            drugObject:{},
            intInfo: []
        };
    },
    methods: {
        //跳转至 详情页面
        goIntDetails(row) {
            console.log(row);
            this.$router.push("/int/intDetails?interactionId="+row.id);
        },
        getIntercations() {
            let obj={
                drugName:this.searchStrDrugA,
                medicine:this.searchStrDrugB
            }
            this.loading = true;
            medicine.interactionSolrSerachAll(obj).then(data => {
                if (data.status == 200) {
                    if(data.data){
                        this.intInfo = data.data;
                        //this.getInteraction();
                    }
                    this.loading = false;
                }
                else {
                    this.loading = false;
                    this.$message.error(data.msg);
                }
            }).catch(error => {
                this.loading = false;
                this.$message.error("获取相互作用列表失败");
            });
        },
        getInteraction(){
            if(this.drugObject && this.drugObject.length>0){
                this.intInfo = [];
                for(var i=0; i<this.drugObject.length; i++){
                    var obj=this.drugObject[i];
                    obj.drugName = this.searchStrDrugA;
                    this.intInfo.push(obj);
                }
            }else{
                this.intInfo = [];
            }
        }
    },
    mounted() {
        this.searchStrDrugB = M.url().medicine ? M.url().medicine : '';
        this.searchStrDrugA =  M.url().drugName ? M.url().drugName : '';
        this.getIntercations();
    },
    watch:{
        "$route":function(){
            if(this.searchStrDrugB != this.$route.query.medicine){
                this.searchStrDrugB = this.$route.query.medicine;
                this.getIntercations();
            }
            if(this.searchStrDrugA != this.$route.query.drugName){
                this.searchStrDrugA = this.$route.query.drugName;
                this.getIntercations();
            }
        }
    }
};
</script>